import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import updateSubButtonStatus from "./updateSubButtonStatus";

export default function getSubTableData(pk_psnjob, isIncHisPartJob) {
    const {areaCode} = this.state;
    const {
        editTable, orgVal, func_type,
        queryModel, currentSelectTreeNode, currentSelectTreeNode2
    } = this.props;

    if (!pk_psnjob) {
        editTable.setTableData(areaCode, {
            rows: []
        });
        updateSubButtonStatus.call(this, false, true);
        return;
    }
    let postData = {
        pk_org: orgVal.refpk,
        areaCode,
        func_type,
        pk_psnjob,
        queryModel,
        isIncHisPartJob,
        tree_node_id: queryModel === '1' ? currentSelectTreeNode : currentSelectTreeNode2
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsLoadSubAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                if (!res.data) {
                    editTable.setTableData(areaCode, {
                        rows: []
                    });
                    this.props.button.setButtonDisabled({
                        'delete': true,
                        'edit': true,
                        'change': true
                    })
                } else {
                    editTable.setTableData(areaCode, {
                        rows: res.data[areaCode].rows
                    });
                    this.props.button.setButtonDisabled({
                        'delete': false,
                        'edit': false,
                        'change': false
                    })
                    /*editTable.setClickRowIndex(areaCode, {
                        record: res.data[areaCode].rows[0].values,
                        index: 0
                    });
                    editTable.focusRowByIndex(areaCode, 0);*/
                }
                updateSubButtonStatus.call(this, false);
            }
        });
}
